<?php

/**
 * Created by PhpStorm.
 * User: 申霖
 * Date: 2019/8/26 0026
 * Time: 下午 7:06
 */
class System extends CI_Controller
{

    /**
     * 读取配置
     * @author 申霖
     * @time 2019/8/26 0026 下午 8:14
     */
    public function home()
    {
        $this->config->load('sevenOxen');
        $data['ak']     = $this->config->item('ak');
        $data['sk']     = $this->config->item('sk');
        $data['bucket'] = $this->config->item('bucket');
        $data['domain'] = $this->config->item('domain');
        $data['name']   = $this->session->item;
        $this->load->view('index/system', $data);

    }

    /**
     * 保存配置
     * @author 申霖
     * @time 2019/8/26 0026 下午 10:34
     */
    public function data()
    {
        $ak     = $this->input->post("ak");
        $sk     = $this->input->post("sk");
        $bucket = $this->input->post("bucket");
        $domain = $this->input->post("domain");
        $config = array(
            'ak'     => '$config[\'ak\']',
            'sk'     => '$config[\'sk\']',
            'bucket' => '$config[\'bucket\']',
            'domain' => '$config[\'domain\']'
        );
        //修改文件
        $str = <<<php
<?php
/**
 * 七牛云存储配置
 */
 
{$config['ak']}     = '$ak'; //AccessKey
{$config['sk']}     = '$sk'; //SecretKey
{$config['bucket']} = '$bucket'; //存储空间名称
{$config['domain']} = '$domain'; //域名
php;

        file_put_contents('./application/config/sevenOxen.php', $str);
        $data['code'] = 200;
        $data['msg']  = '保存成功';
        echo json_encode($data);
    }
}
